﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/Content/angular/angular.js"></script>
</head>
<body>
    <div ng-app="MyApp">
        <div ng-controller="testC">
            <div>
                <input type="button" value="新增" ng-click="AddButton()" />
            </div>
            <ul>
                <li ng-repeat="btn in ButtonInfos">
                    <b>{{btn.Id}}.</b>
                    <span>{{btn.ButtonName}}</span>
                    <span>{{btn.DefaultActionName}}</span>
                    <span>{{btn.DefaultExecution}}</span>
                    <span>{{btn.DefaultPosition}}</span>
                    <span>{{btn.Icon}}</span>
                    <span>{{btn.IsWriteControllerName|typeFilter}}</span>
                    <span>{{btn.SortIndex}}</span>
                    <input type="button" value="编辑" ng-click="EditButton(btn.Id)" />
                    <input type="button" value="删除" ng-click="DeleteButton(btn.Id)" />
                </li>
            </ul>
        </div>
    </div>
    <script type="text/javascript">
        var app = angular.module('MyApp', [], function () { console.log('started') });
        app.controller('testC', function ($scope, $http) {
            $scope.Load = function () {

                $http.get("/api/btnapi").success(function (data, status) {
                    $scope.ButtonInfos = data;
                })
            };
            $scope.AddButton = function () {
                window.location.href = "/Button/Edit";
            };
            $scope.EditButton = function (Id) {
                window.location.href = "/Button/Edit/" + Id;
            };
            $scope.DeleteButton = function (Id) {
                $http.delete("/api/btnapi/" + Id).success(function (objInvokeResult, status) {
                    alert(objInvokeResult.ResultMessage);
                })
            };
            $scope.Load();
        });
        app.filter('typeFilter', function () {
            var f = function (input) {
                return input == '1' ? '是' : '否';
            }
            return f;
        });
    </script>
</body>
</html>
